HAL IWDG migration: List of applicable concepts

This section provides information about the HAL IWDG applicable architecture concepts.

Concepts for IWDG

Concept

Description

Separation of initialization and configuration functions

In HAL2, the HAL_IWDG_Init initializes the HAL IWDG handle and links it to the specified IWDG peripheral instance.

There is no configuration structure neither function, the IWDG parameters max/min time are provided in ms/µs/s to the HAL_IWDG_Start function.

Renaming of the handle structure

The handle structure has been renamed to hal_iwdg_handle_t.

Remove MspInit and MspDeInit callbacks

HAL_IWDG_MspInit() and MspInitCallback are no longer available and have been replaced by a user sequence to initializes and configures the IWDG.

Unitary configuration APIs

New APIs are available to get and set IWDG features.

Introduction of HAL user data set/get APIs

Two functions to set and get user data are available: HAL_IWDG_SetUserData(), HAL_IWDG_GetUserData()

Individual callback registration APIs replace global register and unregister functions

The callback registration is handled by specific functions for each IWDG event. These functions are used to register callback functions for different IWDG events.

HAL implementation with LL inline functions

HAL IWDG APIs now rely on LL APIs rather than performing direct register access.

Define statements and enumerations redirected to LL equivalents

HAL IWDG define statements and enumerations are based on LL define statements.

Removal of hardware-related macros in HAL2

All hardware macros have been removed from the HAL IWDG driver, and equivalent services are ensured through the LL APIs.

Revised and optimized HAL state machine

A state machine has been introduced in HAL2, comprising the following states:

  • HAL_IWDG_STATE_RESET

  • HAL_IWDG_STATE_IDLE

  • HAL_IWDG_STATE_ACTIVE

Revised and optimized HAL API status returns

The HAL IWDG functions were updated to return:

  • HAL_INVALID_PARAM: in case of a NULL p_config structure pointer.

  • HAL_ERROR: in case of an error.

  • HAL_TIMEOUT: in case of a user timeout.

  • HAL_BUSY: in case of an ongoing process.

  • HAL_OK: in case of a successfully completed operation.

Replaced TypeDef suffix with _t in type names

All TypeDef parts of the HAL IWDG driver have been removed and replaced by _t.

Replaced nonmodifiable pointers with const keywords

Const keywords have been added to non-modifiable pointers to ensure that either the pointer itself or the data it points to cannot be modified. This enhances code safety and readability, prevents unintended modifications, and renders code more robust and maintainable.

Assertion implementation and usage in HAL1

The parameters and state are checked using ASSERT_DBG_STATE and ASSERT_DBG_PARAM macro.

Split Peripheral Configuration from Start in System HAL Drivers.

Split the initialization into two function: init and start.

Replace Finite Parameter Defines (Including PPP Instances) with Enum Types at HAL Levels.

Finite parameters (including IWDG instances) have been converted into enumerated types (enums) at HAL level. This improves code readability, maintainability, and type safety.

Add HAL_PPP Prefix to All HAL Peripheral APIs (Defines, Macros, Types, and Functions).

All HAL IWDG functions start with HAL_IWDG. All HAL IWDG enumerations and structures start with hal_iwdg.

Other HAL IWDG changes

Concept

Consideration

The values for Prescaler, Counter, and Window are derived from the minimum and maximum times.

In HAL1, the user manually calculates the values for prescaler, window, and reload and defines them explicitly. However, in HAL2 these values are automatically derived from the parameters provided to the start function.

  • The minimum time corresponds to Window time.

  • The maximum time corresponds to Reset time.

  • The Early Wakeup time is used to set the Early Wakeup Interrupt.

Allow dynamic updates of the IWDG timings based on the dynamic LSI frequency update.

By using the define LSI_VALUE_DYNAMIC, the user can enable dynamic adjustments of the IWDG timings in response to changes in the LSI frequency.

Allow the IWDG to manage the LSI frequency divider (LSI_VALUE / 128).

By using the define LSI_VALUE_DIV_128, the user can manage the LSI frequency.

Configure the IWDG to manage times in seconds (s), milliseconds (ms), and microseconds (µs).

By using the define USE_IWDG_TIME_UNIT (in conf.h file), the user can configure the IWDG time management.

  • HAL_IWDG_TIME_UNIT_US: IWDG driver time unit in microseconds.

  • HAL_IWDG_TIME_UNIT_MS: IWDG driver time unit in milliseconds.

  • HAL_IWDG_TIME_UNIT_S: IWDG driver time unit in seconds.

This time unit apply to the HAL_IWDG_Start, HAL_IWDG_GetMaxTime, HAL_IWDG_GetMinTime, HAL_IWDG_SetMinTime. It does not apply to the HAL_IWDG_GetStep which always returns the WWDG step in microseconds.